﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 系统设置
{
    public partial class EVSet : Form
    {
        carinfor.equipmentConfigInfdata equipconfig = new carinfor.equipmentConfigInfdata();
        carinfor.configIni configini = new carinfor.configIni();
        public EVSet()
        {
            InitializeComponent();
        }

        private void EVSet_Load(object sender, EventArgs e)
        {
            equipconfig = configini.getEquipConfigIni();
            comboBoxSERVOXH.Text = equipconfig.servoXH;
            comboBoxServoMode.SelectedIndex = equipconfig.servocontrolmode;
            comboBoxSERVOCOM.Text = equipconfig.servocom;
            comboBoxSERVOCOMPZ.Text = equipconfig.servocompz;
            comboBoxServoOnRelay.SelectedIndex = equipconfig.servoRelay-1;
            comboBoxServoLockRelay.SelectedIndex = equipconfig.servoLockRelay - 1;
            comboBoxServoUnlockRelay.SelectedIndex = equipconfig.servoUnLockRelay - 1;
            textBoxServoStartDistance.Text = equipconfig.servoStartDistance.ToString();
            textBoxServoEndDistance.Text= equipconfig.servoEndDistance.ToString();
            textBoxEVRelayTime.Text = equipconfig.evRelayTime.ToString();

            comboBoxEVCHARGEXH.Text = equipconfig.EVChargeXH;
            comboBoxEVCHARGEIP.Text = equipconfig.EVChargeIP;
            comboBoxEVCHARGEPORT.Text = equipconfig.EVChargePort;

            comboBoxEVOBDXH.Text = equipconfig.EVOBDXH;
            comboBoxEVOBDIP.Text = equipconfig.EVOBDIP;
            comboBoxEVOBDPORT.Text = equipconfig.EVOBDPort;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            carinfor.equipmentConfigInfdata equipconfigtosave = new carinfor.equipmentConfigInfdata().CopyFrom(equipconfig);
           
            equipconfigtosave.servoXH = comboBoxSERVOXH.Text;
            equipconfigtosave.servocontrolmode = comboBoxServoMode.SelectedIndex;
            equipconfigtosave.servocom = comboBoxSERVOCOM.Text;
            equipconfigtosave.servocompz = comboBoxSERVOCOMPZ.Text;
            equipconfigtosave.servoRelay = comboBoxServoOnRelay.SelectedIndex+1;
            equipconfigtosave.servoLockRelay = comboBoxServoLockRelay.SelectedIndex + 1;
            equipconfigtosave.servoUnLockRelay = comboBoxServoUnlockRelay.SelectedIndex + 1;
            equipconfigtosave.servoStartDistance = int.Parse(textBoxServoStartDistance.Text);
            equipconfigtosave.servoEndDistance = int.Parse(textBoxServoEndDistance.Text);
            equipconfigtosave.evRelayTime = int.Parse(textBoxEVRelayTime.Text);

            equipconfigtosave.EVChargeXH = comboBoxEVCHARGEXH.Text;
            equipconfigtosave.EVChargeIP = comboBoxEVCHARGEIP.Text;
            equipconfigtosave.EVChargePort = comboBoxEVCHARGEPORT.Text;

            equipconfigtosave.EVOBDXH = comboBoxEVOBDXH.Text;
            equipconfigtosave.EVOBDIP = comboBoxEVOBDIP.Text;
            equipconfigtosave.EVOBDPort = comboBoxEVOBDPORT.Text;

            settingform.saveLog("EV参数", equipconfig, equipconfigtosave);
            
            if (configini.writeEquipmentConfig(equipconfigtosave))
                MessageBox.Show("保存成功.", "系统提示");
            else
                MessageBox.Show("数据输入有误,请检查.", "未成功保存");
        }

        private void label15_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxCgjck_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label151_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
